package com.puman.watchtrade.fragment.sell.httpHandler;

import java.io.File;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.puman.watchtrade.fragment.sell.model.SellImgs;
import com.puman.watchtrade.util.Config;
import com.puman.watchtrade.util.DataResult;
import com.puman.watchtrade.util.FileUpload;
import com.puman.watchtrade.util.GlobalData;
import com.puman.watchtrade.util.HttpClent;

public class SellHttpHandler {
	/*
	 * 提交预约
	 */
	public DataResult subOrder(String name, String mobile, SellImgs sellImgs) {
		DataResult dataResult = new DataResult();

		JSONObject params = new JSONObject();
		Map<String, String> textMap = new HashMap<String, String>();

		try {
			if (GlobalData.userInfo == null) {
				params.put("userNo", "");// *
			}else {
				params.put("userNo", GlobalData.userInfo.getUserNo());// *
			}
				params.put("name", name);// *
				params.put("mobile", mobile);// *

		} catch (JSONException e) {
			e.printStackTrace();
		}
		textMap.put("jsonParams", params.toString());
		textMap.put("channel", "app");
//		Map<String, String> fileMap = new HashMap<String, String>();
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < sellImgs.sellimgList.size(); i++) {
			String filepath = sellImgs.sellimgList.get(i).getImageUrl().replace("file://", "").replace("file:/", "");
			list.add(filepath);
		}
		String path = Config.baseUrlStr + Config.sellInfo;
		
		String resultJson = FileUpload.formUpload(path, textMap, list);
		JSONObject result;
		try {
			result = new JSONObject(resultJson);
			dataResult.flag = result.getBoolean("flag");
			dataResult.msg = result.getString("msg");
		} catch (JSONException e) {

		}
		return dataResult;
	}

}
